package group.rober.saber.jdbc;

import com.google.common.base.CaseFormat;

/**
 * 默认名称转换器,字段名和属性名,表名和类名之间相互转换. SYS_USER表转为类SysUser,USER_ID字段转为userId属性等
 * Created by tisir<yangsong158@qq.com> on 2017-05-27
 */
public class DefaultNameConverter implements NameConverter {

    public String getPropertyName(String columnName) {
        if(columnName==null)return columnName;
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, columnName);
    }

    public String getPropertyName(int column) {
        return null;
    }

    public String getColumnName(String propertyName) {
        if(propertyName==null)return propertyName;
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, propertyName);
    }

    public String getClassName(String tableName) {
        if(tableName==null)return tableName;
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, tableName);
    }

    public String getTableName(Class<?> clazz) {
        if(clazz==null)return null;
        String name = clazz.getSimpleName();
        return CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, name);
    }
}
